<template>
	<view class="">
		<view class="mainpadding bai_text textcenter" style="background-color: #ffa126;" v-if="dataAll.type==1">代驾</view>
		<view class="mainpadding bai_text textcenter" style="background-color: #00ac8f;" v-if="dataAll.type==2">顺风车</view>
		<view class="mainpadding">
			<view class="xiaolan titletext bold" v-show="dataAll.status==20">司机已接单</view>
			<view class="xiaolan titletext bold" v-show="dataAll.status==30">进行中</view>
			<view class="xiaohong titletext bold" v-show="dataAll.status==40">待确认</view>
			<view class="xiaolv titletext bold" v-show="dataAll.status==50">已完成</view>
			<view class="mainpadding_top ffffff radius">
				<view class="titletext hei_text bold">出发地</view>
				<view class="margin_top hui_text main_size bold">{{dataAll.start_address}}</view>
			</view>
			<view class="mainpadding_top ffffff radius">
				<view class="titletext hei_text bold">目的地</view>
				<view class="margin_top hui_text main_size bold">{{dataAll.end_address}}</view>
			</view>
			<view class="mainpadding_top ffffff radius flexbetween" @click="phone(dataAll.ccr_mobile)">
				<view class="titletext hei_text bold">客户电话：{{dataAll.ccr_mobile}}</view>
				<u-icon name="phone" size="20" color="#00ac8f"></u-icon>
			</view>
			<view class="mainpadding_top ffffff radius">
				<view class="titletext hei_text bold">订单信息</view>
				<view class="flexbetween margin_top">
					<view class="hei_text bold main_size">订单编号</view>
					<view class="xiaohui">{{dataAll.order_no}}</view>
				</view>
				<view class="flexbetween margin_top">
					<view class="hei_text bold main_size">创建时间</view>
					<view class="xiaohui">{{dataAll.createtime_text}}</view>
				</view>
				<view class="flexbetween margin_top">
					<view class="hei_text bold main_size">出发时间</view>
					<view class="xiaohui">{{dataAll.cf_time}}</view>
				</view>
				<view class="flexbetween margin_top">
					<view class="hei_text bold main_size">距离</view>
					<view class="xiaolan">{{dataAll.distance}}km</view>
				</view>
				<view class="flexbetween margin_top">
					<view class="hei_text bold main_size">订单金额</view>
					<view class="xiaolan">￥{{dataAll.pay_price}}</view>
				</view>
				<view class="flexbetween margin_top" v-if="dataAll.status==40 || dataAll.status==50">
					<view class="hei_text bold main_size">行车时长</view>
					<view class="xiaohui">{{dataAll.sc_text}}</view>
				</view>
			</view>
			<view class="submitbtn margin_top6" v-if="dataAll.status==20" @click="shangche">确认用户上车</view>
			<view class="submitbtn margin_top6" v-if="dataAll.status==30" @click="xiache">已到达目的地</view>
			<view class="submitbtn margin_top6" v-if="dataAll.status==40" @click="over">完成订单</view>
		</view>
		
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				listid: "",
				dataAll: {},
			}
		},
		onLoad(options) {
			this.listid = options.id
			this.init()
		},
		methods: {
			over() {//完成
				httpRequest.modal('提示', '确认订单完成？', true, (res) => {
					if (res) {
						httpRequest.request('/api1/order/qrwc', 'GET', {
							id: this.listid
						}, false, false, true).then(res => {
							if (res.code == 1) {
								this.init()
							}else{
								httpRequest.toast(res.msg);
							}
						}).catch(err => {
							httpRequest.toast(err.msg);
						})
					}
				})
			},
			xiache() {//下车
				httpRequest.modal('提示', '确认用户下车？', true, (res) => {
					if (res) {
						httpRequest.request('/api1/order/cgxc', 'GET', {
							id: this.listid
						}, false, false, true).then(res => {
							if (res.code == 1) {
								this.init()
							}else{
								httpRequest.toast(res.msg);
							}
						}).catch(err => {
							httpRequest.toast(err.msg);
						})
					}
				})
			},
			shangche() {//上车
				httpRequest.modal('提示', '确认用户上车？', true, (res) => {
					if (res) {
						httpRequest.request('/api1/order/cgsc', 'GET', {
							id: this.listid
						}, false, false, true).then(res => {
							if (res.code == 1) {
								this.init()
							}else{
								httpRequest.toast(res.msg);
							}
						}).catch(err => {
							httpRequest.toast(err.msg);
						})
					}
				})
			},
			init() { //用户信息
				httpRequest.request('/api/order/detail', 'GET', {
					id: this.listid
				}, false, false, true).then(res => {
					if (res.code == 1) {
						this.dataAll = res.data
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			// getcoupon() { //获取优惠券
			// 	httpRequest.request('/api1/user/userCoupon', 'GET', {
			// 		pay_price: this.pay_price
			// 	}, false, false, true).then(res => {
			// 		this.couponlist = res.data
			// 	}).catch(err => {
			// 		httpRequest.toast(err.msg);
			// 	})
			// },
			// xuanzeyh() {
			// 	if (this.pay_price == "") {
			// 		httpRequest.toast("请输入支付金额")
			// 		return
			// 	}
			// 	if (!this.couponlist.length) {
			// 		httpRequest.toast("暂无可用优惠券")
			// 		return
			// 	}
			// 	this.couponShow = true
			// },
			// checkcoupon(item) { //选择优惠券
			// 	this.coupon_id = item.coupon_id
			// 	this.coupon_name = item.name
			// 	this.couponShow = false
			// },
			linexiaPay() {
				this.Payshow = false
				httpRequest.request('/api/order/editPayPrice', 'GET', {
					pay_price: this.pay_price,
					pay_type: this.pay_type,
					id: this.listid,
					coupon_id: this.coupon_id
				}, false, false, true).then(res => {
					if (res.code == 1) {
						if (this.pay_type == 20) {
							httpRequest.toast(res.msg);
							setTimeout(() => {
								uni.navigateBack(1)
							}, 1000)
						}
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			phone(p) {
				uni.makePhoneCall({
					phoneNumber: p.toString()
				}).catch((e) => {})
			},
		}
	}
</script>

<style scoped>
	.bglan {
		background-color: #3478f5;
	}
</style>